package com.fs.jzzn.pojo;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;

import lombok.Data;
import lombok.EqualsAndHashCode;

import com.fs.base.pojo.PEntity;
import com.fs.base.utils.ApplicationUtils;
import com.fs.base.utils.ExcelUtils;

/**
 * @author TiddlerCJ
 * @desc 工程支出明细
 */
@Entity
@Table(name="p_expense_item")
@Data@EqualsAndHashCode(callSuper=false)
public class ExpenseItem extends PEntity {
	private String expenseNo;			//支出单号
	private String costType;		 	//费用类别
	private Double money;				//支出金额
	private String billsNo;				//凭单号
	private String pNo;					//路段编号
	private String department;			//关联项目部		
	private String costDate;				//支出日期
	private String costUser;				//报销人
	
	
	public static List<ExpenseItem> excelDataFormat(List<List<String>> data) {
		List<ExpenseItem> list = new ArrayList<ExpenseItem>();
		for(List<String> rowData: data){
			list.add(excelData2Bean(rowData));
		}
		return list;
	}
	
	//支出对象	标题说明	类别	金额(元)	凭单号	路段编号	关联项目部	支出日期
	private static ExpenseItem excelData2Bean(List<String> row) {
		row = ExcelUtils.dataLenFomart(row, 8);
		ExpenseItem item = new ExpenseItem();
		item.setCostUser(row.get(0));
		if(StringUtils.isBlank(item.getCostUser())){
			item.setCostUser(ApplicationUtils.User().getNickName());
		}
		item.setRemark(row.get(1));
		item.setCostType(row.get(2));
		try {
			Double money = Double.parseDouble(row.get(3));
			item.setMoney(money);
		} catch (Exception e) {
			System.err.println("支出金额格式有误："+row.get(3) );
		}
		item.setBillsNo(row.get(4));
		item.setPNo(row.get(5));
		item.setDepartment(row.get(6));
		item.setCostDate(row.get(7));
		item.setCreaterId(ApplicationUtils.userId());
		item.setCreateTime(new Date());
		return item;
	}
	
	
}
